package com.example.springboot.service;

import com.example.springboot.entity.MerchantOrderReview;
import com.example.springboot.mapper.MerchantOrderReviewMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MerchantOrderReviewService {
    @Autowired
    private MerchantOrderReviewMapper merchantOrderReviewMapper;

    public MerchantOrderReview getReviewByOrderId(Integer orderId) {
        return merchantOrderReviewMapper.selectByOrderId(orderId);
    }

    // 新增：根据 review_id 获取评价
    public MerchantOrderReview getReviewByReviewId(Integer reviewId) {
        return merchantOrderReviewMapper.selectByPrimaryKey(reviewId);
    }

    public void addReview(MerchantOrderReview review) {
        merchantOrderReviewMapper.insert(review);
    }

    public void updateReview(MerchantOrderReview review) {
        merchantOrderReviewMapper.updateByPrimaryKey(review);
    }

    public int deleteReview(Integer reviewId) {
        return merchantOrderReviewMapper.deleteByPrimaryKey(reviewId);
    }

    public List<MerchantOrderReview> getAllReviews() {
        return merchantOrderReviewMapper.selectAll();
    }

    public List<MerchantOrderReview> getReviewsByMerchantId(Integer merchantId) {
        return merchantOrderReviewMapper.selectByMerchantId(merchantId);
    }

    public List<MerchantOrderReview> getReviewsByUserId(Integer userId) {
        return merchantOrderReviewMapper.selectByUserId(userId);
    }
}